
#ifndef _TTG_UTILS_UTILMANAGER_
#define _TTG_UTILS_UTILMANAGER_
#include "Common/Definitions.h"

#include "Runtime.Low/Services.h"
#include "UtilManagerDll.h"
#include "Parameters.h"
#include "InternalSets.h"
#include "UtilityProps.h"

namespace ttg
{
	namespace utils
	{
		//Service, that provides access to utilities.
		//Note: it's singleton.
		class UtilManager :public ttg::services::Service
		{
			private:
				static const double UPDATE_RATE;
				static UtilManager *ref;
			private:
				ttg_internal::utils::InternalSets *internal_sets;
				ttg::math::uint64 TimeEventID;
				//Handler for time event.
				void onTick(double time);
				//Loads required utility.
				static void init(UtilityProps &utility);
				//Updates device section in GlobalInfo.
				static void updateDevices(std::vector<ttg::services::DeviceInfo *> &devices);
				//Unloads utility.
				static void close(const char *name);
			protected:
				//Creates manager.
				UtilManager();
				//Service member. Tries to bind UtilManager.dll.
				virtual void startUnSafe(std::vector<ttg::services::Service *> &deps, const char *params);
				//Stops updating and unbind UtilManager.dll.
				virtual void stopUnSafe();
			public:
				//Tries to show tray icon.
				//In case of error makes record in the logger.
				void activateWindow();
				//Loads external utility (according to properties).
				inline void addUtility(UtilityProps &props)
				{ init(props); }
				//Loads external utility (with given name).
				inline void addUtility(const char *name)
				{ addUtility(UtilityProps(name)); }
				//Returns root of set with internal parameters.
				inline ttg_internal::utils::InternalSets *getInternalSets()
				{ return internal_sets; }
				//Returns reference to instance.
				static inline UtilManager *getRef()
				{ return ref == NULL ? (ref = new UtilManager()) : ref; }
		};
	}
}

#endif

